# -!- coding: utf-8 -!-
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
脚本类，用来对组合好的参数进行循环执行，依次带入组合参数请求。可加入对响应结果断言） 
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

from parameter.qbmsloanCs import parameter
import requests
from logger import Logger


logger = Logger("qbmsloan").get_log()

parameter = parameter()

url = 'https://test.qb.msxiaodai.com'
headers = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36',
            'content-Type': 'application/json'
        }

def jinjian():
    logger.info('进件接口测试开始---------')
    furl = url + '/galaxy/process/userInfo'
    data_list = parameter.get_jinjian_data('F:\PythonProject\InterfaceTest\\files\\qbmsloan.xls')
    result = []
    for data in data_list:
        status = data[1]
        req1 = requests.post(furl, json=data[0], headers=headers)
        fhcode = str(req1.status_code)
        if fhcode == '200':
            if req1.text != status:
                logger.info("失败案例的进件信息：%s", data[0])
                logger.info("失败案例的响应信息：%s", req1.text)
                result.append('false')
            else:
                result.append('true')
        else:
            logger.info("http error info：%s", fhcode)
    return(result)


def payout():
    logger.info('代付穿透接口测试开始--------->')
    furl = url + '/qbmsloan/pay/transferRequest'
    data_list = parameter.get_payout_data('F:\PythonProject\InterfaceTest\\files\\qbmsloan.xls')
    result = []
    for data in data_list:
        status = data[1]
        req1 = requests.post(furl, json=data[0], headers=headers,timeout=15)
        fhcode = str(req1.status_code)
        respond = eval(req1.text)['retCode']
        # print('jiegou',respond)
        if fhcode == '200':
            if respond != status:
                logger.info("失败代付信息：%s", data[0])
                logger.info("失败代付的响应信息：%s", req1.text)
                result.append('false')
            else:
                result.append('true')
        else:
            logger.info("http error info：%s", fhcode)
    return (result)


def pushContract():
    logger.info('合同信息推送接口测试开始--------->')
    furl = url + '/qbmsloan/transaction/pushLoanContract'
    data_list = parameter.get_contract_data('F:\PythonProject\InterfaceTest\\files\\qbmsloan.xls')
    result = []
    for data in data_list:
        status = data[1]
        req1 = requests.post(furl, json=data[0], headers=headers,timeout=15)
        fhcode = str(req1.status_code)
        respond = eval(req1.text)['status']
        #print('jiegou',type(respond))
        if fhcode == '200':
            if respond != status:
                logger.info("失败的合同推送信息：%s", data[0])
                logger.info("失败的合同推送响应信息：%s", req1.text)
                result.append('false')
            else:
                result.append('true')
        else:
            logger.info("http error info：%s", fhcode)
    return (result)


def repaymentPlan():
    logger.info('放款信息和还款计划推送接口测试开始--------->')
    furl = url + '/qbmsloan/transaction/pushLoanRecord'
    data_list = parameter.get_paymentPlan_data('F:\PythonProject\InterfaceTest\\files\\qbmsloan.xls')
    result = []
    for data in data_list:
        # print(data)
        status = data[1]
        req1 = requests.post(furl, json=data[0], headers=headers,timeout=15)
        fhcode = str(req1.status_code)
        respond = str(eval(req1.text)['status'])
        #print('jiegou',type(respond))
        if fhcode == '200':
            if respond != status:
                logger.info("失败的还款计划推送信息：%s", data[0])
                logger.info("失败的还款计划推送响应信息：%s", req1.text)
                result.append('false')
            else:
                result.append('true')
        else:
            logger.info("http error info：%s", fhcode)
    return (result)


def repayment():
    logger.info('还款信息推送接口测试开始--------->')
    furl = url + '/qbmsloan/loan/batchSavePaymentHistoryVOList'
    data_list = parameter.get_payment_data('F:\PythonProject\InterfaceTest\\files\\qbmsloan.xls')
    result = []
    for data in data_list:
        # print(data)
        status = data[1]
        req1 = requests.post(furl, json=data[0], headers=headers,timeout=15)
        fhcode = str(req1.status_code)
        respond = str(eval(req1.text)['status'])
        #print('jiegou',type(respond))
        if fhcode == '200':
            if respond != status:
                logger.info("失败的还款计划推送信息：%s", data[0])
                logger.info("失败的还款计划推送响应信息：%s", req1.text)
                result.append('false')
            else:
                result.append('true')
        else:
            logger.info("http error info：%s", fhcode)
    return (result)


if __name__ == '__main__':
    repayment()


